using System;
using System.Collections.Generic;
using System.Text;
using SpoonCore2.Client;

namespace SpoonCore2.Message.Filter
{
	public interface IMessageFilter
	{
		Type InfoType { get;}
		void Decode(IMessageFilterInfo info, ref byte[] data);
		void Encode(IMessageFilterInfo info, ref byte[] data);
	}

	public abstract class IMessageFilter<T> : IMessageFilter where T : IMessageFilterInfo
	{
		public abstract void Receive(T info, ref byte[] data);
		public abstract void Send(T info, ref byte[] data);

		public Type InfoType
		{
			get { return typeof(T); }
		}

		public void Decode(IMessageFilterInfo info, ref byte[] data)
		{
			Receive((T)info, ref data);
		}

		public void Encode(IMessageFilterInfo info, ref byte[] data)
		{
			Send((T)info, ref data);
		}
	}
}